PowerMac Oberon offers a module Sys which exports the most frequently used types, variables, and procedures of the Macintosh toolbox. Additional toolbox interfaces can be implemented on demand, as described in this text.
Toolbox constants, variables, and types can be declared as described in Inside Macintosh. Records, however, must be aligned according to the 68K conventions (2 byte boundaries) instead of the PowerPC conventions (4 byte boundaries). Therefore, toolbox records have to be declared with a special alignment option, e.g.:
TYPE
Point = RECORD [Sys.align68K]
v, h: INTEGER;
END;
To write an interface to a toolbox procedure, you have to do the following:
a) Declare a procedure variable with the interface as described in Inside Macintosh, e.g.:
VAR GetMouse: PROCEDURE (mouseLoc: Point);
b) Initialize the procedure variable with the corresponding procedure from the toolbox library. This can be done using the procedure Sys.Assign, e. g.:
The first parameter of Assign is the name of the toolbox procedure the second parameter is the address of the procedure variable to be initialized.
Caution
- Never use a record as VAR-Parameter. Always pass records as a VAL-Parameter.
- Pointers returned by the toolbox must not be saved into Oberon pointer variables, but should be casted to a LONGINT. Otherwise, the garbage collector will start collecting memory in your toolbox.
The following example shows a complete module that uses the toolbox procedure GetMouse.
MODULE Mouse;
IMPORT Sys, SYSTEM;
TYPE
Point = RECORD [Sys.align68K]
v, h: INTEGER
END;
GetMouse: PROCEDURE (mouseLoc: Point);
PROCEDURE GetMousePos* (VAR x, y: INTEGER);
VAR p: Point;
BEGIN
GetMouse (p);
x := p.h; y := p.v
END GetMousePos;
BEGIN
Sys.Assign ("GetMouse", SYSTEM.ADR (GetMouse));
ASSERT (GetMouse # NIL)
END Mouse.
Module SYSTEM
Module SYSTEM allows the user to break the Oberon type rules and to access machine dependent information. Under PowerMac Oberon, SYSTEM includes the procedures defined in the Oberon report in addition to PowerPC specific procedures:
- SYSTEM.GETREG(n, v) reads register n into the variable v. n must be a constant expression in the range 0..66. The type of v must be a basic type, a pointer or a procedure type. Registers 48 .. 66 can only be read in supervisor mode.
- SYSTEM.PUTREG(n, e) writes expression e to register n. n must be a constant expression in the range 0..66. The type of e must be a basic type, a pointer or a procedure type. Registers 48 .. 66 can only be written in supervisor mode.
Register numbers
General purpose registers (0..31)
0..31 Rx or FPx, depending on the second operand of GETREG or PUTREG
1 SP (stack pointer)
2 SB (static base)
31 FP (frame pointer)
Control registers (32..66; 48..66 are priviledged)